package lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MakeCaluator {
    public static void main(String[] args) {
    new MyCaluatorFrame();
    }
}

class MyCaluatorFrame extends Frame{
   public MyCaluatorFrame() {
       //三个窗口
       TextField tx1 = new TextField(10);
       TextField tx2 = new TextField(10);
       TextField tx3 = new TextField(10);

       //一个标签
       Label label = new Label("+");
       //一个按钮
       Button bt1=new Button("=");
        bt1.addActionListener(new MyCaluatorListener(tx1,tx2,tx3));


        setLayout(new FlowLayout());
        add(tx1);
        add(label);
        add(tx2);
        add(bt1);
        add(tx3);
        this.setVisible(true);
        pack();
   }
}
//监听器类
class MyCaluatorListener implements ActionListener{
    //获取三个变量
     private TextField tx1,tx2,tx3;
    public MyCaluatorListener(TextField tx1, TextField tx2, TextField tx3){
      this.tx1=tx1;
      this.tx2=tx2;
      this.tx3=tx3;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        //计算
        int a=Integer.parseInt(tx1.getText());
        int b=Integer.parseInt(tx2.getText());

        //返回
        tx3.setText(""+(a+b));
        //关闭
        tx1.setText("");
        tx2.setText("");
    }
}
